package com.yixun.controller;

import com.yixun.entity.YxSysUser;
import com.yixun.service.UserService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * @author lbx create by 2021/6/1 10:06
 * @apiNote UserController
 */
@RestController
public class UserController {
    @Resource
    private UserService userService;
    
    
    /**
     * @param map TODO
     * @return java.lang.Integer
     * @apiNote createUser 增加用户
     */
    @PostMapping("/addUser")
    public Integer createUser(@RequestBody HashMap<String, String> map) {
        return userService.createUser(map);
    }
    
    /**
     * @param map 当前页 条数
     * @return java.util.List<com.yixun.entity.YxSysUser>
     * @apiNote getUsersByPage 获取用户列表
     */
    @PostMapping("/getUserList")
    public List<YxSysUser> getUsersByPage(@RequestParam HashMap<String, Integer> map) {
        return userService.getUsersByPage(map);
    }
    
    /**
     * @param map 例： ids:[1,2,3]
     * @return java.lang.Integer
     * @apiNote deactivateUser 停用账号
     */
    @PostMapping("/deactivateUser")
    public Integer deactivateUser(@RequestBody HashMap<String, List<Long>> map) {
        System.out.println(map);
        return userService.deactivateUser(map);
    }
    /**
     * @param map 用户ID 新密码
     * @return java.lang.Integer
     * @apiNote changePassword 修改密码
     */
    @PostMapping("/changePassword")
    public Integer changePassword(@RequestBody HashMap<String, Object> map){
        return userService.changePassword(map);
    }
    /**
     * @param map 用户字段封装
     * @return java.lang.Integer
     * @apiNote updateUser 更新用户信息
     */
    @PostMapping("/updateUser")
    public Integer updateUser(@RequestBody HashMap<String, Object> map){
        return userService.updateUser(map);
    }
    
}
